perm filename MAN9.TEX[TEX,ALS] blob
sn#601461 filedate 1981-07-30 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00003 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 \input manhdr[tex,dek] % This is the TEX user manual source text
C00004 00003 chapterbegin 22. {Alignment}
C00027 ENDMK
C⊗;
\input manhdr[tex,dek] % This is the TEX user manual source text
\titlepage
\tenpoint
\null\vskip-46pt
\hbox to size{\:<Stanford Artificial Intelligence Laboratory\hfill September
1979}
\hbox to size{\:<Memo AIM-317.3\hfill(fourth printing)}
\vskip .25in
\hbox{\:<Computer Science Department}
\hbox{\:<Report No. STAN-CS-78-675}
\vfill
\ctrline{\:<TAU EPSILON CHI, a system for technical text}
\vskip .25in
\ctrline{$\copyright$ 1979 by the American Mathematical Society}
\vfill
{\baselineskip 7pt
\:f The author wishes to thank the many individuals who made
helpful comments on the first drafts of this manual, and especially Leo
Guibas for his help in producing copies on experimental graphics printing
equipment. Thanks are also due to
the National Science Foundation and to the Office of Naval Research,
for helping to support the author's research
under grants \hbox{MCS 72-03752 A03} and
\hbox{N00014-76-C-0330}. Since the METAFONT
system for typeface design is still under development, the type fonts used
herein are only initial approximations to the eventual ones.\par}
\eject\titlepage
chapterbegin 22. {Alignment}
A novice \TEX\ user can prepare manuscripts that involve mathematical
formulas but no complicated tables; but a \TEX\ Master can prepare complicated
tables using {\≡\halign≡\} or {\≡\valign≡\}. In this chapter, if you're
ready for it, you can learn to be a \TEX\ Master.\xskip
(And the next chapter---which
talks about the design of {\≡\output≡\} routines---will enable you to
become a Grandmaster.)
\par\vfill\eject
The $\langle$alignment entries$\rangle$ consist of zero or more $\langle$row$
\rangle$s; and a $\langle$row$\rangle$ is one or more entries separated by
{\≡⊗≡\}'s and followed by {\≡\cr≡\}. In general if the preamble contains $n$
$\langle$format$\rangle$s
$$\tabskip 0pt plus 10000000000pt
\halign to size{\ctr{$# $}\tabskip 0pt⊗#⊗\ctr{$# $}⊗#⊗\ctr{$#
$}⊗#⊗\ctr{$# $}⊗#\hfill\tabskip 0pt plus 10000000000pt\cr
\langle u↓1\rangle\hbox{\tt\char'43}\langle v↓1\rangle⊗{\≡⊗≡\}⊗
\langle u↓2\rangle\hbox{\tt\char'43}\langle v↓2\rangle⊗{\≡⊗≡\}⊗\;\;\cdots\;\;
⊗{\≡⊗≡\}⊗\langle u↓n\rangle\hbox{\tt\char'43}\langle v↓n\rangle\cr
\noalign{\vskip 11pt plus 3pt minus 8pt
\hbox{and if there are $m$ rows each containing $n$ entries}
\vskip 11pt plus 3pt minus 8pt}
\langle x↓{11}\rangle⊗{\≡⊗≡\}⊗\langle x↓{12}\rangle⊗{\≡⊗≡\}⊗
\cdots⊗{\≡⊗≡\}⊗\langle x↓{1n}\rangle⊗{\≡\cr≡\}\cr
\noalign{\penalty 1000}
\langle x↓{21}\rangle⊗{\≡⊗≡\}⊗\langle x↓{22}\rangle⊗{\≡⊗≡\}⊗
\cdots⊗{\≡⊗≡\}⊗\langle x↓{2n}\rangle⊗{\≡\cr≡\}\cr
\noalign{\penalty 1000}
\vdots⊗⊗\vdots⊗⊗⊗⊗\vdots\cr
\noalign{\penalty 1000}
\langle x↓{m1}\rangle⊗{\≡⊗≡\}⊗\langle x↓{m2}\rangle⊗{\≡⊗≡\}⊗
\cdots⊗{\≡⊗≡\}⊗\langle x↓{mn}\rangle⊗{\≡\cr≡\}\cr
\noalign{\vskip 11pt plus 3pt minus 8pt
\hbox{we will obtain $mn$ fleshed-out entries}
\vskip 11pt plus 3pt minus 8pt}
\langle u↓1\rangle\langle x↓{11}\rangle\langle v↓1\rangle⊗⊗
\langle u↓2\rangle\langle x↓{12}\rangle\langle v↓2\rangle⊗⊗\cdots⊗⊗
\langle u↓n\rangle\langle x↓{1n}\rangle\langle v↓n\rangle\cr
\noalign{\penalty 1000}
\langle u↓1\rangle\langle x↓{21}\rangle\langle v↓1\rangle⊗⊗
\langle u↓2\rangle\langle x↓{22}\rangle\langle v↓2\rangle⊗⊗\cdots⊗⊗
\langle u↓n\rangle\langle x↓{2n}\rangle\langle v↓n\rangle\cr
\noalign{\penalty 1000}
\vdots⊗⊗\vdots⊗⊗⊗⊗\vdots\cr
\noalign{\penalty 1000}
\langle u↓1\rangle\langle x↓{m1}\rangle\langle v↓1\rangle⊗⊗
\langle u↓2\rangle\langle x↓{m2}\rangle\langle v↓2\rangle⊗⊗\cdots⊗⊗
\langle u↓n\rangle\langle x↓{mn}\rangle\langle v↓n\rangle\cr}$$
by repeatedly copying the preamble format information.
\danger Now here's what \TEX\ does with the $mn$ fleshed-out entries: The
natural width of each entry {\≡\hbox{≡\}$\langle u↓j\rangle\langle x↓{ij}
\rangle\langle v↓j\rangle${\≡}≡\} is determined; and the {\sl maximum}
natural width is computed in each column. Suppose that $w↓j$ is the maximum natural
width in the $j$th column; then each fleshed-out entry in that column
is replaced by the
box ``{\≡\hbox to ≡\}$w↓j${\≡{≡\}$\langle u↓j\rangle\langle x↓{ij}
\rangle\langle v↓j\rangle${\≡}≡\}''. Thus, all entries in a particular column
now have the same width. Finally these boxes are welded together to make the
$m$ rows, by inserting $n+1$ elements of glue in each row (before the first
box, between boxes, and after the last box). The glue to use in this welding
process has previously been specified by ``{\≡\tabskip≡\}$\langle$glue$\rangle$''.
The $m$ row boxes are finally appended to the current vertical list.
\par\vfill\end
\danger If you don't understand what was said so far, look back at the matrix
example and reread the above until you understand. Because there are also some
refinements that we shall now discuss.\xskip (a) After any {\≡\cr≡\} you can
type ``{\≡\noalign{≡\}$\langle$vlist$\rangle${\≡}≡\}'', and this $\langle$vlist$
\rangle$ will simply appear in its place among the aligned row boxes. The
$\langle$vlist$\rangle$
in this case usually contains vertical glue, penalty specifications,
or horizontal rules; but it might contain anything that is allowed in restricted
vertical mode, even another {\≡\halign≡\}.\xskip(b) If some row has fewer than
$n$ entries, i.e., if the {\≡\cr≡\} of some row occurs before there have been
$n-1$ {\≡⊗≡\}'s, all remaining columns of the row are set to null boxes
regardless of their format.\xskip
(This is not necessarily the same as ``{\≡\hbox{≡\}$
\langle u↓j\rangle\langle v↓j\rangle${\≡}≡\}''; the preamble formats are
simply ignored.)\xskip (c) If you specify {\≡\tabskip≡\}$\langle$glue$\rangle$
in the preamble, the $n+1$ globs of glue that weld together the final row
boxes will be different, so you can get different spacing between columns.
Here's how it works: The glue placed before column 1 is the {\≡\tabskip≡\} glue
in effect when the {\≡\halign≡\} control sequence itself appears; the glue
that replaces a {\≡⊗≡\} or {\≡\cr≡\} is the {\≡\tabskip≡\} glue in effect
when that {\≡⊗≡\} or {\≡\cr≡\} appears in the preamble.
\danger Warning: Any spaces you type in the $\langle$format$\rangle$s of the
preamble will be taken seriously! Don't start a new line after a {\≡⊗≡\} unless
you intend a corresponding space to be there in every column.\xskip (You may, of
course, start a new line after {\≡\cr≡\} without inserting an unwanted space,
or you can type ``{\≡⊗\!≡\}'' and go to a new line.)\xskip The same applies to
spaces in the aligned entries; {\sl always be extra careful with your use of
spaces inside {\≡\halign≡\}.}
\danger Another warning: Don't use a construction like ``{\≡$#$≡\}'' in your
$\langle$format$\rangle$s if the corresponding column entries might be
null. Otherwise \TEX\ will scan ``{\≡$$≡\}'' and think display math is
intended, and this probably will lead to hopeless confusion.\xskip
(The matrix example
above has ``{\≡$\ctr{#}$≡\}'' instead of ``{\≡\ctr{$#$}≡\}'' for precisely this
reason. Another safe possibility would be ``{\≡\ctr{$# $}≡\}''.)
\ddanger You can have {\≡\halign≡\} or {\≡\valign≡\} within {\≡\halign≡\}
or {\≡\valign≡\} (for example, matrices within aligned equations). In order
to allow this, \TEX\ insists that {\≡{≡\} and {\≡}≡\} be balanced in alignment
entries, so that it is possible to distinguish which level of alignment
corresponds to a given {\≡⊗≡\} or {\≡\cr≡\}. Consider, for example, the
extremely simple alignment
$$\vbox{\halign{#\hfill\cr
{\≡\halign{\ctr{#}\cr≡\}\cr
{\≡≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡\}$\langle$entry$\rangle${\≡\cr}≡\}\quad.\cr}}$$
When \TEX\ begins to scan the alignment entry, it scans the string of
tokens ``{\≡\ctr{≡\}\penalty0
$\langle$entry$\rangle${\≡\cr}...≡\}''; and the appearance
of ``{\≡\ctr≡\}'' causes \TEX\ to look for {\≡\ctr≡\}'s argument. This
argument begins with ``{\≡{≡\}'', so the scanning continues until the matching
``{\≡}≡\}''. However, when the {\≡\cr≡\} is encountered after
$\langle$entry$\rangle$, \TEX\ is supposed to insert the matching ``{\≡}≡\}''
from the preamble. If $\langle$entry$\rangle$ itself contains a use of
{\≡\halign≡\}, there will be {\≡\cr≡\}'s in the middle of $\langle$entry$\rangle$;
so \TEX\ doesn't simply look for the first {\≡\cr≡\}. Instead it ignores the
tokens {\≡⊗≡\} and {\≡\cr≡\} until finding one that is not enclosed in
braces, thereby correctly determining the argument to {\≡\ctr≡\}.
\ddanger Defined control sequences in the preamble are not usually expanded
until the alignment entries are being processed.
However, a control sequence following ``{\≡\tabskip≡\}$\langle$glue$\rangle$''
in the preamble might be expanded, since a $\langle$glue$\rangle$ specification
might involve control sequences. For example, ``{\≡\tabskip 0pt \ctr{#}≡\}''
will effectively be expanded by \TEX\ to ``{\≡\tabskip 0pt \hfill # \hfill≡\}''
while the preamble is being scanned, because \TEX\ won't know (when it gets
to ``{\≡\ctr≡\}'') whether or not the expansion of this control sequence will
begin with ``{\≡plus 1pt≡\}'' or some other continuation of the glue
specification.
\danger In the rest of this chapter we shall discuss two worked-out examples.
First suppose that we want to typeset three
pairs of displayed formulas whose = signs are to be aligned, such as
$$\vcenter{\halign{\rt{$#$}⊗\lft{$\null=#$}\qquad
⊗\rt{$#$}⊗\lft{$\null=#$}\qquad
⊗\rt{$#$}⊗\lft{$\null=#$}\cr
V↓i⊗v↓i-q↓iv↓j,⊗X↓i⊗x↓i-q↓ix↓j,⊗U↓i⊗u↓i,\qquad\hbox{for }i≠j;\cr
V↓j⊗v↓j,⊗X↓j⊗x↓j,⊗U↓j⊗u↓j+\sum↓{i≠j}q↓iu↓i.\cr}}\eqno(13)$$
We could do this with three {\≡\eqalign≡\}'s, but let's not, since our
current goal is to learn more about the general {\≡\halign≡\} construction.
One solution is to type
$$\vbox{\halign{#\hfill\cr
{\≡$$\vcenter{\halign{≡\}$\langle$alignment preamble$\rangle${\≡\cr≡\}\cr
{\≡V≡↓i⊗v≡↓i-q≡↓iv≡↓j,⊗X≡↓i⊗x≡↓i-q≡↓ix≡↓j,⊗U≡↓i⊗u≡↓i,\qquad\hbox{for }i≡spose
/=j;\cr≡\}\cr
{\≡V≡↓j⊗v≡↓j,⊗X≡↓j⊗x≡↓j,⊗U≡↓j⊗u≡↓j+\sum≡↓{i≡spose/=j}q≡↓iu≡↓i.\cr}}\eqno(13)$$≡\}\cr
}}$$
with some suitable alignment preamble.\xskip
(It sometimes helps to figure out how you
want to type the alignment entries before you design the preamble; there's a
tradeoff between ease of typing the entries and ease of constructing the
preamble.)\xskip One suitable preamble is
$$\vbox{\halign{#\hfill\cr
{\≡$\rt{#}$⊗\lft{$\null=#$}\qquad≡\}\cr
{\≡⊗$\rt{#}$⊗\lft{$\null=#$}\qquad≡\}\cr
{\≡⊗$\rt{#}$⊗\lft{$\null=#$}≡\}\cr}}\quad.$$
Note the {\≡\null≡\}s here: they ensure proper spacing before the = signs,
because the equations are being broken into two parts. Study this example
carefully and you'll soon see how to make useful alignments.
\danger \exno 22.1: What would happen if ``{\≡\vcenter≡\}'' were replaced by
``{\≡\vbox≡\}'' in the above example?
\danger If we didn't
have to include an equation number like ``(13)'', the {\≡\vcenter≡\} could
have been omitted; but then there would have been a possible page break between
the two equations, and the equations would not have been centered on the line.\xskip
(The only effect of the {\≡$$≡\}'s in ``{\≡$$\halign{...}$$≡\}'' is to insert
{\≡\dispskip≡\} glue above and below the alignment.)\xskip One way to prevent a
page break would be to insert ``{\≡\noalign{\penalty 1000}≡\}'' between
the lines. And one way to center the equations would be to vary the
tabskip glue, as in the definition of {\≡\eqalignno≡\} in Appendix B. But it
is much easier to use {\≡\vcenter≡\}.
\danger The second example is slightly more complex, but once you master it
you will have little or no trouble with other tables. Suppose you want to
specify this:
$$\vbox{\tabskip 0pt
\def\|{\vrule height 9.25pt depth 3pt}
\def\.{\hskip-10pt plus 10000000000pt}
\hrule
\hbox to 150pt{\|\.AT&T Common Stock\.\|}
\hrule
\halign to 150pt{#\tabskip 0pt plus 100pt
⊗\hfill#⊗#⊗\ctr{#}⊗#⊗\hfill#⊗#\tabskip 0pt\cr
\|⊗\.Year\.\hfill⊗\|⊗\.Price\.⊗\|⊗\.Dividend\.\hfill⊗\|\cr
\noalign{\hrule}
\|⊗1971⊗\|⊗41--54⊗\|⊗$\$$2.60⊗\|\cr
\noalign{\hrule}
\|⊗2⊗\|⊗41--54⊗\|⊗2.70⊗\|\cr
\noalign{\hrule}
\|⊗3⊗\|⊗46--55⊗\|⊗2.87⊗\|\cr
\noalign{\hrule}
\|⊗4⊗\|⊗40--53⊗\|⊗3.24⊗\|\cr
\noalign{\hrule}
\|⊗5⊗\|⊗45--52⊗\|⊗3.40⊗\|\cr
\noalign{\hrule}
\|⊗6⊗\|⊗51--59⊗\|⊗.95\spose*⊗\|\cr
\noalign{\hrule}}
\vskip 3pt
\hbox{*(first quarter only)}}$$
including all those horizontal and vertical lines. The table is to be 150
points wide. Here is one way to do it, letting the tabskip glue expand to
give the column widths (so that, for example, the ``Price'' column will turn out
to be exactly one en-dash-width wider than the ``Year'' column):
$$\halign{\hskip 10pt#\cr
{\≡$$\vbox{\tabskip 0pt≡\}\cr
{\≡\def\|{\vrule height 9.25pt depth 3pt}≡\}\cr
{\≡\def\.{\hskip-10pt plus 10000000000pt}≡\}\cr
{\≡\hrule≡\}\cr
{\≡\hbox to 150pt{\|\.AT&T Common Stock\.\|}≡\}\cr
{\≡\hrule≡\}\cr
{\≡\halign to 150pt{#\tabskip 0pt plus 100pt≡\}\cr
{\≡⊗\hfill#⊗#⊗\ctr{#}⊗#⊗\hfill#⊗#\tabskip 0pt\cr≡\}\cr
{\≡\|⊗\.Year\.\hfill⊗\|⊗\.Price\.⊗\|⊗\.Dividend\.\hfill⊗\|\cr≡\}\cr
{\≡\noalign{\hrule}≡\}\cr
{\≡\|⊗1971⊗\|⊗41--54⊗\|⊗$\$$2.60⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗2⊗\|⊗41--54⊗\|⊗2.70⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗3⊗\|⊗46--55⊗\|⊗2.87⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗4⊗\|⊗40--53⊗\|⊗3.24⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗5⊗\|⊗45--52⊗\|⊗3.40⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗6⊗\|⊗51--59⊗\|⊗.95\spose*⊗\|\cr\noalign{\hrule}}≡\}\cr
{\≡\vskip 3pt≡\}\cr
{\≡\hbox{*(first quarter only)}}$$≡\}\cr}$$
\vskip-6pt
\danger Here is an explanation of this rather long sequence of commands:
The control sequence ``{\≡\|≡\}'' is defined to be a vertical rule that
guarantees appropriate spacing of baselines between individual rows.\xskip
(\TEX\ doesn't use {\≡\baselineskip≡\} and {\≡\lineskip≡\} before or after
horizontal rules.)\xskip
The alignment is defined in such a way that the {\≡\tabskip≡\}
glue is zero at the left and right of the alignment, but it is ``{\tt 0pt plus
100pt}'' between columns; this glue will therefore
expand to make the columns equally
spaced. There are seven (not three) columns, since the vertical rules are
considered to be
columns. The preamble has just ``{\≡#≡\}'' for the columns that are to be
vertical rules; the ``Year'' column and ``Dividend'' column both have format
``{\≡\hfill#≡\}'', causing them to be right-justified, while the ``Price''
column has format ``{\≡\ctr{#}≡\}''. The top row of the table appears
before the {\≡\halign≡\}, since it does not have to be aligned with
the other rows. In the second row of the table, an extra ``{\≡\hfill≡\}''
has been typed after ``Year'' and ``Dividend'', to compensate for the
fact that the columns are being right-justified yet the titles are supposed to
be centered. The special control sequence ``{\≡\.≡\}'' is also placed around
these title words; this is somewhat tricky. It has the effect of telling
\TEX\ to ignore the width of the title words when computing the column widths.
The asterisk in the final row of the table is preceded by ``{\≡\spose≡\}'' in
order to make it zero-width, otherwise the decimal points wouldn't line up
properly.
\danger Another way to get vertical and horizontal rules into tables is to
typeset without them, then back up (using negative glue) and insert them.
\danger The control sequence {\≡\valign≡\} is analogous to {\≡\halign≡\}, but
with rows and columns changing r\A oles. In this case {\≡\cr≡\} marks the
bottom of a column. The boxes in each row will line up as if their reference
points were at the bottom; in other words, their depth is effectively set
to zero by modifying their height.\enddanger
\par\vfill\end